<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增供应商管理')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-supplier-add">
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">供应商编码：</label>
                        <div class="col-sm-8">
                            <input name="supplierCode" class="form-control" type="text" maxlength="16" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">供应商名称：</label>
                        <div class="col-sm-8">
                            <input name="supplierName" class="form-control" type="text" maxlength="30" required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">联系人：</label>
                        <div class="col-sm-8">
                            <input name="contactPerson" class="form-control" type="text" maxlength="6" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">电话：</label>
                        <div class="col-sm-8">
                            <input name="telephone" class="form-control" type="text" maxlength="16" required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">手机：</label>
                        <div class="col-sm-8">
                            <input name="mobilePhone" class="form-control" type="text" maxlength="11">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">邮箱：</label>
                        <div class="col-sm-8">
                            <input name="email" class="form-control" type="text" maxlength="50" >
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">地址：</label>
                        <div class="col-sm-8">
                            <input name="address" class="form-control" type="text" maxlength="100" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">级别：</label>
                        <div class="col-sm-8">
                            <select name="supplierLevel" class="form-control" th:with="type=${@dict.getType('wms_level')}" required>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">发票抬头：</label>
                        <div class="col-sm-8">
                            <input name="invoiceLookedUp" class="form-control" type="text" maxlength="64" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">发票税率：</label>
                        <div class="col-sm-8">
                            <input name="invoiceTax" class="form-control" type="text" maxlength="4" required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">发票种类：</label>
                        <div class="col-sm-8">
                            <select name="invoiceType" class="form-control m-b" th:with="type=${@dict.getType('sys_invoice')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">备注：</label>
                        <div class="col-sm-8">
                            <textarea name="remark" class="form-control" maxlength="200"></textarea>
                        </div>
                    </div>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "basis/supplier"
        $("#form-supplier-add").validate({
            onkeyup: false,
            rules:{
                supplierCode:{
                    minlength: 2,
                    maxlength: 16,
                    remote: {
                        url: prefix + "/checkSupplierCodeUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "supplierCode": function() {
                                return $.common.trim($("#supplierCode").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                email:{
                    email:true,
                },
                mobilePhone:{
                    isPhone:true,
                },
                invoiceTax:{
                    min:0,
                    max:1,
                    number:true,
                },
            },
            messages: {
                "supplierCode": {
                    remote: "供应商编码已存在"
                },
                "email": {
                    remote: "Email格式不对"
                },
                "mobilePhone":{
                    remote: "手机号码格式不对"
                },
                "invoiceTax":{
                    remote: "必须输入合法的数字(包含小数)"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-supplier-add').serialize());
            }
        }
    </script>
</body>
</html>